package javaclickers.javaclickers.mobile;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;

import android.util.Log;

public class Parameters {
	private Socket socket;
	private ObjectOutputStream oos;
	private ObjectInputStream ois;
	private MainActivity mainActivity;
	private ContestarProblema contestarProblema = null;
	private int tiempo;

	public Parameters(String ip, MainActivity mainActivity) {
		try {
			this.mainActivity = mainActivity;
			socket = new Socket(ip, 9900);
			oos = new ObjectOutputStream(socket.getOutputStream());
			ois = new ObjectInputStream(socket.getInputStream());
			this.mainActivity.setOkConexion(true);
		} catch (UnknownHostException e) {
			Log.e("error", e.getMessage(), e);
			this.mainActivity.setOkConexion(false);
		} catch (IOException e) {
			Log.e("error", e.getMessage(), e);
			this.mainActivity.setOkConexion(false);
		}
	}

	public void cerrarConexiones() {
		try {
			oos.close();
			ois.close();
			socket.close();
		} catch (IOException e) {
			Log.e("error", e.getMessage(), e);
		}
	}

	public Socket getSocket() {
		return socket;
	}

	public void setSocket(Socket socket) {
		this.socket = socket;
	}

	public ObjectOutputStream getOos() {
		return oos;
	}

	public void setOos(ObjectOutputStream oos) {
		this.oos = oos;
	}

	public ObjectInputStream getOis() {
		return ois;
	}

	public void setOis(ObjectInputStream ois) {
		this.ois = ois;
	}

	public ContestarProblema getContestarProblema() {
		return contestarProblema;
	}

	public void setContestarProblema(ContestarProblema contestarProblema) {
		this.contestarProblema = contestarProblema;
	}

	public int getTiempo() {
		return tiempo;
	}

	public void setTiempo(int tiempo) {
		this.tiempo = tiempo;
		try {
			socket.setSoTimeout((tiempo * 10000) + 20000);
		} catch (SocketException e) {
			Log.e("error", e.getMessage(), e);
		}
	}

}
